package org.jsola.contract.helper;

import org.jsola.common.SafeKit;
import org.jsola.contract.constant.EnterpriseSealType;
import org.jsola.contract.constant.FontType;
import org.jsola.contract.constant.PersonSealType;
import org.jsola.contract.constant.SealColor;
import org.jsola.contract.dto.SealAddDTO;
import org.jsola.contract.dto.SealUpdateDTO;
import org.jsola.contract.entity.SealDO;
import org.jsola.contract.query.SealQuery;
import org.jsola.contract.service.ISealService;
import org.jsola.contract.vo.SealVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.contract.core.AbstractTest.SITE_ID;



/**
 * 印章
 *
 * @author JanusMix
 */
@Component
public class SealTestHelper extends BaseTestHelper {
    
    @Autowired
    private ISealService sealService;

    /**
     * 生成add测试数据
     * @return SealAddDTO
     */
    public SealAddDTO getSealAddDTO(){
        SealAddDTO sealAddDTO = new SealAddDTO();
        sealAddDTO.setSubjectId(getRandomValue("varchar",32));
        sealAddDTO.setName(getRandomValue("varchar",255));
        sealAddDTO.setSourceId(getRandomValue("varchar",32));
        sealAddDTO.setDescription(getRandomValue("varchar",1000));
        sealAddDTO.setAccountId(getRandomValue("varchar",40));
        sealAddDTO.setIsLegalPerson(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        sealAddDTO.setLegalPerson(getRandomValue("varchar",50));
        sealAddDTO.setLegalPersonPicture(getRandomValue("text",2147483647));
        sealAddDTO.setSealString(getRandomValue("text",2147483647));
        sealAddDTO.setContent(getRandomValue("varchar",255));
        sealAddDTO.setColor(SealColor.RED.getValue());
        sealAddDTO.setFont(FontType.SIMKAI.getValue());
        sealAddDTO.setFontSize(getRandomValue("varchar",30));
        sealAddDTO.setPersonalSealType(PersonSealType.SQUARE.getValue());
        sealAddDTO.setEnterpriseSealType(EnterpriseSealType.STAR.getValue());
        sealAddDTO.setText(getRandomValue("varchar",255));
        sealAddDTO.setRoundText(getRandomValue("varchar",255));
        sealAddDTO.setRowText(getRandomValue("varchar",255));
        sealAddDTO.setBottomText(getRandomValue("varchar",255));
        sealAddDTO.setIssue(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        sealAddDTO.setStatus(SafeKit.getInteger(getRandomValue("int",11)));
        return sealAddDTO;
    }


    /**
     * 生成update测试数据
     * @return SealUpdateDTO
     */
    public SealUpdateDTO getSealUpdateDTO(SealVO sealVO){
        return sealService.selectDOById(sealVO.getId(), SITE_ID).to(SealUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return SealQuery
     */
    public SealQuery getSealQuery() {
        SealQuery sealQuery = new SealQuery();
        List<SealDO> sealDOList = sealService.list(new SealDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(sealDOList)) {
            SealDO sealDO = sealDOList.get(0);
            sealQuery = sealDO.to(SealQuery.class);
        }
        return sealQuery;
    }

    /**
     * 保存示例
     * @return SealVO
     */
    public SealVO saveSealExample(){
        SealAddDTO addDTO = this.getSealAddDTO();
        SealVO sealVO = sealService.save(addDTO,buildTokenUser());
        return sealVO;
    }


}

